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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on 'onclick' how do you access the form's values?

Status
Not open for further replies.

Candyb

Technical User
Oct 2, 2001
12
CA
Hi,

I have a html form and I don't want to send it anywhere but to my javascript function. If i put the form's button to onclick, how do I access the form's values to insert as parameters in my javascript function.

For instance:

<form name=&quot;tips&quot;>
<table width=&quot;750&quot; border=&quot;0&quot;>
<select name=&quot;display&quot;>
<option>Select A Display Mode</option>
<option value=&quot;tipsheetprint.xsl&quot;> Print</option>
<option value=&quot;tipsheetpda.xsl&quot;>PDA</option>
<option value=&quot;tipsheet2.xsl&quot;>Screen</option>
</select>
<select name=&quot;type&quot;>
<option>Select A Display Mode</option>
<option value=&quot;tipsheetprint1.xsl&quot;> Print1</option>
<option value=&quot;tipsheetpda2.xsl&quot;>PDA2</option>
<option value=&quot;tipsheet3.xsl&quot;>Screen3</option>
</select>

</table>
<input name=&quot;submit&quot; value=&quot;submit&quot;
onclick=&quot;showIt(display, type)&quot;>
</form>

In above for showIt parameters I want 'display' to be the selected option the user has chosen.(what is correct syntax?)

function showIt(display,type)//accepts str values
{
blah
}

Thanks,

Candyb
 
Pass the actual form to your function:

<input name=&quot;submit&quot; value=&quot;submit&quot; onclick=&quot;showIt(this.form)&quot;>

then, in your function:

function showIt(form)
{
var displayValue = form.display.value;
var typeValue = form.display.value;

Blahdeblah;

}

the variables will store the values your user selected when they hit the submit button.
 
Try this :

<script>
function showIt () {
var my_var = document.tips.display.value
var my_var2 = document.tips.type.value
alert(my_var + '\n' + my_var2)
}
</script>
<form name=&quot;tips&quot;>
<table width=&quot;750&quot; border=&quot;0&quot;>
<select name=&quot;display&quot;>
<option>Select A Display Mode</option>
<option value=&quot;tipsheetprint.xsl&quot;> Print</option>
<option value=&quot;tipsheetpda.xsl&quot;>PDA</option>
<option value=&quot;tipsheet2.xsl&quot;>Screen</option>
</select>
<select name=&quot;type&quot;>
<option>Select A Display Mode</option>
<option value=&quot;tipsheetprint1.xsl&quot;> Print1</option>
<option value=&quot;tipsheetpda2.xsl&quot;>PDA2</option>
<option value=&quot;tipsheet3.xsl&quot;>Screen3</option>
</select>

</table>
<input type=&quot;button&quot; value=&quot;submit&quot; onclick=&quot;showIt()&quot;>
</form> Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top