By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

Java script - forms..please help ASAP!

P: 2
hi!

i'm new to java script. i'm doing a web page, where i can increment the value of a text field by pressing a button. Each time i press the button, the value in the text field should be incremented

i wrote a code for this and it returned an error

Line: 9
Char: 2
Error: Object Expected
Code: 0

The code is given below. Please tell me if there's an error in the code, or if you have a different solution - please let me know. i'm open to all ideas. would be nice if i got a solution as early as possible. thank you so much!


[HTML]<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

function encode(text)
{
var temp= parseint(text);
temp +=1;
text = temp.toString();
document.form1.result.value = text;
}
// - End of JavaScript - -->
</SCRIPT>

</HEAD>
<BODY bgcolor="beige">


<FORM name="form1">
<table border=0><tr><br><td>
<INPUT TYPE=Button VALUE="submit" onClick="encode(this.form.input.value)"><tr><td>
Result:<td><INPUT NAME="result" TYPE=Text>

</table>
</FORM>
</BODY>
</HTML>[/HTML]
Oct 10 '07 #1
Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

welcome to TSDN ...

have a look at the following (fixed) code:

[HTML]<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function encode(text) {
var temp= parseInt(text);
temp +=1;
text = temp.toString();
document.form1.result.value = text;
}
</SCRIPT>
</HEAD>
<BODY bgcolor="beige">
<FORM name="form1">
<table border=0>
<tr>
<td><INPUT TYPE=Button VALUE="submit" onClick="encode(this.form.result.value)">
Result:
<INPUT NAME="result" TYPE=Text value="0">
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
[/HTML]
kind regards

ps: that is a hotfix :) ... following things were wrong: parseInt - js is case-sensitive, in your onclick-function you refered this.form.input.value - but input should be result, tabletags were completly messed up ... , value for the input type text should be 0 per default or you have to handle NaN in your function ...

hints: the language attribute for the script tag is deprecated use type="text/javascript" instead ..., write tag- and attribute-names in lower case, put quotes around attribute values ...
Oct 10 '07 #2

P: 2
Thanks a bunch gits!!!!!!!!!!!

its working perfectly!

thank you again!!!

warm regards
Oct 11 '07 #3

gits
Expert Mod 5K+
P: 5,390
hi ...

glad to hear that ;) ... post back to the forum anytime you have more questions ...

kind regards
Oct 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.