fred asselyon Posted December 8, 2005 Share Posted December 8, 2005 Let's say that i have a textbox with the name "java". I want to make a code that can compare the contents of that text box when people submit. I used the onsubmit to call a function in the head tag. But the problem is, I don't know what's the name of the textbox variable! should i use $java or what? I've noticed a website the uses "document.[name of the form].[value/name].checked" as variables that contains the boolean data from a radio button. Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 9, 2005 Share Posted December 9, 2005 Do this:<input type="text" id="java"><input type="button" value="Click" onclick="doThing()">And in the head section:<script type="text/javascript">function doThing(){document.getElementById("java").attribute=value}</script> Link to comment Share on other sites More sharing options...
fred asselyon Posted December 9, 2005 Author Share Posted December 9, 2005 document.getElementById("java").attribute=value This really helps, thanks! What kind of text i should use to replace "attribute?"What is attribute? Sorry, but I'm so green in Javascripting... Link to comment Share on other sites More sharing options...
aspnetguy Posted December 9, 2005 Share Posted December 9, 2005 inorder to compare the value you would access its value like this var javaValue = document.getelementById('java').value; you can then put it through some if statements to see if it meets your requirements.For example if it can't be empty if(javaValue.length == 0){ alert('you cannot leave this field blank!'); document.getElementById('java').focus(); //puts focus back to java field} Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 9, 2005 Share Posted December 9, 2005 When I say attribute, i mean this:<input type="text" value="thing" id="test">The bold parts are the attributes, or the 'settings' of the html element. Does that help a bit? Link to comment Share on other sites More sharing options...
fred asselyon Posted December 14, 2005 Author Share Posted December 14, 2005 That helps.. thanks for both of ya! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now