Jump to content

Form problem


fred asselyon

Recommended Posts

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...