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

document.theform.field.value ... driving me nuts ;'/ 1

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I'm tryign to do something really simple -

Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>

<body>

<form id="rateform2" name="rateform"><strong>Rate the video Black Solo:</strong>
<p>

<input type="hidden" name="ID" value="350977" />
<input type="radio" name="rateval" value="1">1
<input type="radio" name="rateval" value="2">2
<input type="radio"  name="rateval" value="3">3
<input type="radio"  name="rateval" value="4">4
<input type="radio" name="rateval" value="5">5
<input type="radio"  name="rateval" value="6">6
<input type="radio" name="rateval" value="7">7
<input type="radio" name="rateval" value="8">8
<input type="radio" name="rateval" value="9">9
<input type="radio" name="rateval" value="10">10
<input value="Go" type="button" onclick='alert(document.form.rateform.rateval.value)'>
</p>
<div id="result"></div>
</form>

</body>

</html>

I've also tried it with:

Code:
onclick='alert(document.rateform.rateval.value)'

..and also:

Code:
onclick='alert(this.form.rateval.value)'

..but to no avail.

I'm far from a JS expert, but I'm sure the document.formnam.field.value should work, shouldn't it? What am I doing wrong?

TIA!

Andy
 
Thanks, that got me on the right track :)

Cheers

Andy
 
MMm,, this is pissing me off :(

The following example, works (locally), but as soon as I put it on the site, it won't :/ (get to the first "here" alert, then seems to stop)

Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Rate the video Amateur 69 Positi</title>

<script>

function radio_button_checker() {
 var radio_choice = 0;
 for (counter = 0; counter < rateform.rateval.length; counter++) {
	 if (rateform.rateval[counter].checked ) {
		 var thevalue = counter + 1;
		 alert("test value was " + thevalue);
		 return thevalue;
	 }
 }
 alert("Please select a rating!");
}

function do_stuff() {
 alert("here");
 var rating = radio_button_checker();
 alert("here bla bla");
 if (rating > 0) {
   alert(rating);
/*   xmlhttpPost("[URL unfurl="true"]http://www.onlybestsex.com/cgi-bin/links/rate.cgi");*/[/URL]
   return false;
 } else {
 alert("here 2");

   return false;
 }
  alert("here 3");
 return false;
}

</script>

</head>

<body>

<form id="rateform" name="rateform"><strong>Rate the video</strong>
<p>

<input type="hidden" name="ID" value="350980" />
<input type="radio" id="rate" name="rateval" value="1">1
<input type="radio" id="rate" name="rateval" value="2">2
<input type="radio" id="rate" name="rateval" value="3">3
<input type="radio" id="rate" name="rateval" value="4">4
<input type="radio" id="rate" name="rateval" value="5">5
<input type="radio" id="rate" name="rateval" value="6">6
<input type="radio" id="rate" name="rateval" value="7">7
<input type="radio" id="rate" name="rateval" value="8">8
<input type="radio" id="rate" name="rateval" value="9">9
<input type="radio" id="rate" name="rateval" value="10">10
<input value="Go" type="button" onclick='return do_stuff();'>
</p>
<div id="result"></div>
</form>

</body>

</html>

Anyone got any ideas? I'm simply out of em :(

TIA

Andy
 
[0] If you are meant to assign id's to checkboxes, make them all distinct. Id is meant to be unique for each element. (So the easiest correct to it is to not to assgin any id to checkboxes explicitly.)

[1] Always fully reference the form (by name) with the leading document object. It is not taken as omnipresence for browsers. Neither if you have in mind referencing the form by id, ... more so. In the latter case, explicit use of getElementById() is warranted for being cross-browser.
[tt]
function radio_button_checker() {
var radio_choice = 0;
for (counter = 0; counter < [red]docuemnt.[/red]rateform.rateval.length; counter++) {
if ([red]document.[/red]rateform.rateval[counter].checked ) {
[red]//[/red]var thevalue = counter + 1;
[blue]var thevalue=document.rateform.rateval.value;[/blue]
alert("test value was " + thevalue);
return thevalue;
}
}
alert("Please select a rating!");
[blue]return 0; //make sure it is consistent with the setting of their values and the condition "rate>0" in the calling function[/blue]
}
[/tt]
 
amendment
Upon re-read what I posted, this line is obviously not what I intended to convey and should be sure replaced.
>[self]var thevalue=document.rateform.rateval.value;
[tt]var thevalue=document.rateform.rateval[red][count][/red].value;[/tt]
 
Thanks, managed to get it working now :)

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top