Jump to content

It wont work :{


Yuval200

Recommended Posts

Hello :)I got a proglem, and it's getting me nuts.I'm trying to do a form, and an "onsubmit" event. Now, when the user submit the form, it tries to see if he wrote the data good.The form:

  <form action="outPost.php" method="POST" onsubmit="form_validation()" name="send" id="send" style="margin-left: 15px">	<!--Page ended: 19/6/2006 21:19 -->   <table cellspacing="0" cellpadding="0">    <tr style="height: 35px">	 <td style="width: 175px; padding: 1px 1px 1px 10px">Sender's name:</td>	 <td style="width: 120px"><input type="text" class="sendText" style="height: 20px" name="name" id="name"></td>    </tr>    <tr style="height: 95px">	 <td valign="top" class="invBorder" style="width: 175px; border-bottom-width: 1px; padding: 1px 1px 5px 10px">Message content:</td>	 <td valign="top" class="invBorder" style="width: 150px; border-bottom-width: 1px; padding-bottom: 5px"><textarea class="sendText" rows="4" cols="50" name="content" id="content"></textarea></td>	</tr>	<tr style="height: 38px">	 <td valign="top" align="right" colspan="2" style="padding: 5px 1px 1px 1px">	  <input class="sendBotton" type="reset" value="Reset" />  	  <input class="sendBotton" type="submit" value="submit" /> 	 </td>	</tr>   </table>  </form>

The JS part:

function form_validation() { //This is the function that do the validation of the sending message form. 31/8/06 11:12	try {		if (document.send.name == "")			throw "name_error";					if (document.send.content == "")			throw "content_error";	}		catch(error) {		if (error == "name_error")			alert("You must write your name!");					if (error == "contect_error")			alert("You must add content to your post!");	}}

If you could please point out what are the mistakes I'm making.Another thing please- is there a trim function (Trims the white space from the start and the end of the string) like PHP has? If you could help, I'll be greatfull.Thanks,Yuval :)

Link to comment
Share on other sites

I had troubles with javascript many times, so there might be a simpler solution, I would try:<form ... onsubmit="form_validation(obj); return false;" ...in the form andfunction form_validation(this) {...catch(error) {if (error == "name_error")alert("You must write your name!");else if (error == "contect_error")alert("You must add content to your post!");else obj.submit();}in javascript.I don't know any direct function in JS to trim strings.

Link to comment
Share on other sites

Ok, thanks skym, the problem that I had was that I should of wrote the "value" after that "name". But I did used that "return false", thanks :).That thing I have now is that I want to do a function that disables that send bottom, I already have an idea, but I want to do the following thing:document.form.botton.disabled = TRUE/FALSE.I might miswrote that, but basicly I want to replace the "form", "botton" and "TRUE/FALSE" with varibles. Problem is that JS isn't like PHP with it's $ sign. So my question is - how can I replace those following things with varibles?(I know I had some spelling mistakes, I'm sorry. If you haven't understood me, I will try to rephrase it again).If you could please help me.. :)Thanks,Yuval :)

Link to comment
Share on other sites

If you have variables named "xoo" and "gahgah" in your javascript, and as long as they're defined, just go:document.xoo.gahgah.disabled="true".It'll work. :)

Link to comment
Share on other sites

If you have variables named "xoo" and "gahgah" in your javascript, and as long as they're defined, just go:document.xoo.gahgah.disabled="true".It'll work. :)
Well I tried to do something like that, or it was abit different, I can't remmbmer. It didn't worked.. I did something else and it did worked, nevermind :)The question that I want to ask now (If it's ok)- I have saw several sites, including IPB forum systems, that opened a popup thing.Now, I saw the W3S tutorial about popups in JS, it showed some ways such as the alert and promat box, but the one that I didn't found was an example on how to open a window popup, like when you guys write a new post, and press "BB Code Help" or "Show All" onther the smilies box.Thanks, and I'm sorry for having so many questions.Yuval
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...