Forum Moderators: open

Message Too Old, No Replies

Trying to get a button to work with JS

         

outdoorxtreme1

3:52 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



Can anyone tell me what I am doing wrong. I can't seem to get a button to call some JS code.

<input id="Submit" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Submit" onclick="self.clicked=this.value" />

kaled

4:19 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this in the same location. If it fails try validating the html code.
<input type="button" value="Click Me" onclick="alert(this.value)" />

I'm not sure why you're using a submit button.

self.clicked = this.value; is interesting. Presumably you wish to test self.clicked later.

Kaled.

outdoorxtreme1

4:40 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



I am submitting to a php script. Here is the code I have so far:

<html>
<head>
<title>Submit a Trip Report</title>
<script>
<!--
var date = new Date();

function validate(screen) {
if (screen=="Submit") {
return true;//overrides the validation...
var errmsg = "";
with (document.forms[0]) {
if (!triplocation.value) errmsg += "\nYour trip report has no <title>.";
if (!author.value) errmsg += "\nPlease identify the report <author>.";
if (!report.value) errmsg += "\nPlease fill in the report <body> section.";
}
if (errmsg) {
alert("Sorry...\nYou have not filled out the form completely.\n" + errmsg + "\n\nPlease complete the form and 'SUBMIT' again...");
return false;
}
}
return true;
}

//-->
</script>
</head>
<body>

<!--UNIQUE PAGE CONTENT-->

<form method="post" action="/tct/submit.php">
<table>
<tr>
<td valign="top" id="fillinform">
<table WIDTH="450">
<tr>
<td valign="top" colspan="2"><strong>Trip / Title:</strong><br />
<input type="text" size="29" maxlength="50"
name="triplocation" value="" />
<br />
</td>
<td valign="top">
<strong>River Condition:</strong><br />
<select name="rivercondition" size="1">

<option value="too high">too high</option>
<option value="very high">very high</option>
<option value="high">high</option>
<option value="medium high">med. high</option>
<option value="medium">medium</option>
<option value="medium low">med. low</option>
<option selected="selected" value="low boatable">low boatable</option>
<option value="too low">too low</option>
</select></td>

</tr></table>

<table>
<tr>
<td valign="top" id="fillinform">
<strong>Type your trip report below:</strong><br />
<textarea name="report" rows="15" cols="55" wrap="on" class="input350"></textarea>
</td>
</tr>
</TABLE>
<TABLE WIDTH="273">
<TR>
<td valign="top">
<p>
<input id="Submit" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Submit" onclick="self.clicked=this.value" />&nbsp;
</td>
</tr></table>
</form>

<!--END OF UNIQUE CONTENT-->
</body>
</html>