Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<input> tag problem

Status
Not open for further replies.

pmcmicha

Technical User
May 25, 2000
353
I have the following code which works without any problem:

<input type=&quot;button&quot; name=&quot;Submit&quot; value=Submit&quot; onClick=&quot;go()&quot;>


The user comes to the website, selects two options from the drop down menus and then clicks on submit. Submit then takes those options and passes it to the 'go' function.


Now I would like to use an image in place of the default button, so I have this code, but it does not work:

<input type=&quot;image&quot; src=&quot;../Images/submit.gif&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; onClick=&quot;go()&quot;>


The only response I got back was the page putting the selected information in the URL section since I had not defined the method type in the form tag.


Everything I have looked at, seems to indicate that I am not missing anything or doing anything wrong. Could someone shed some light on this problem?

Thanks in advance.
 
Show the code for the go() function.

There's always a better way. The fun is trying to find it!
 
Here is the html page (example, has been shortened):

<form name=&quot;dc&quot;>
<p align=&quot;center&quot;>
<b>Group:</b>
<select align=&quot;center&quot; name=&quot;ex1&quot; size=&quot;1&quot; onChange=&quot;redirect(this.options.selectedIndex)&quot;>
<option value=&quot;example.html&quot;>---Make a selection---</option>
<option>Test 1</option>
</select>

<b>Log:</b>
<select name=&quot;ex2&quot; size=&quot;1&quot;>
<option value=&quot;---Make a selection---&quot;></option>
</select>
</p>

<p align=&quot;center&quot;>
<input type=&quot;image&quot; src=&quot;../Images/submit.gif&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; onClick=&quot;go()&quot;>
</p>

<script language=&quot;Javascript&quot;>
<!--
var groups=document.dc.ex1.options.length
var group=new Array(groups)
for (w=0; w<groups; w++)
group[w]=new Array()
group[1][0]=new Option(&quot;test.log&quot;, &quot;ND/test.log.html&quot;)
group[1][1]=new Option(&quot;test1.log&quot;, &quot;ND/test1.log.html&quot;)

var temp=document.dc.ex2

function redirect(x) {
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (y=0;y<group[x].length;y++) {
temp.options[y]=new Option(group[x][y].text,group[x][y].value)
}
}

function go() {
location=temp.option[temp.selectedIndex].value
}
//-->
</html>


Let me know if you need anything else.
 
I can't understand some of the code. For instance what is location? (in the go function), temp? (in the redirect fuction).

Aside from that, the problem you are having is that when you change from type 'button' to type 'image', you are then submitting the form as soon as you click it. 'image' and 'submit' types are identical in function. 'button' type does not submit the form on click.

What you can do is, instead of using an onClick event associated with the button, use an onSubmit fucntion in the form tag:

onSubmit=&quot;return go()&quot;

then you can return true or false in the go() function which will determine whether the form is submitted or not, but the function will be run regardless.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top