JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 16th, 2000, 11:43 AM
RayRay RayRay is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Hong Kong
Posts: 71 RayRay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 50 sec
Reputation Power: 9
I want to check the empty text in the form with javascript and php. What's wrong in this program? How to solve it? Thanks!

<html>
<script language="javascript">
<!--

option_desc=new makearray(<? echo $num-1; ?> );

function checkform() {

<?
for ($i=0; $i<$num; $i++) {
?>
if (document.poll_form.option_desc[<? echo $i; ?>].value=="") {
alert("Text<? echo $i+1; ?> is empty.");
document.poll_form.option_desc[<? echo $i; ?>].focus();
return false;
}
<?
}
?>
return true;
}

//-->
</script>

<body>
<form method="post" action="" name="poll_form" onsubmit="return checkform();">
<?
for ($i=0; $i<$num; $i++) {
?>
<p>
<input type="text" name="option_desc[<? echo $i; ?>]" size="50">
</p>
<?
}
?>
<input type="submit" name="submit">
</form>
</body>
</html>

[This message has been edited by RayRay (edited June 16, 2000).]

Reply With Quote
  #2  
Old June 16th, 2000, 10:49 PM
firepages's Avatar
firepages firepages is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: Perth West Australia
Posts: 741 firepages User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
The javascript routine is client side - the onSubmit() executes client side before the form is posted and therfore before the values in option_desc[] exist-

if you send the page to itself via the form ,then validation will occur but your validation routine runs before the form is actually submitted. onSubmit() return true; - will only send the form & post the variables if the validation was successful.

If you see what I mean?

Simon

------------------
Simon Wheeler
FirePages -DHTML/PHP/MySQL

Reply With Quote
  #3  
Old June 17th, 2000, 06:27 PM
RayRay RayRay is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Hong Kong
Posts: 71 RayRay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 50 sec
Reputation Power: 9
Now, is the javascript doesn't work. It can't validation the text data.
How to solve it?

Reply With Quote
  #4  
Old June 17th, 2000, 11:02 PM
firepages's Avatar
firepages firepages is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: Perth West Australia
Posts: 741 firepages User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Hi RayRay - listen - apologies my last answer was gibberish - not sure where I was coming from - the form below works!

<html>
<script language="javascript">
<!--
function checkform() {
<?php $num=3;?>
<?
for ($i=0; $i<$num; $i++) {
?>
if (document.poll_form.option_desc<? echo $i; ?>.value=="") {
alert("Text<? echo $i+1; ?> is empty.");
document.poll_form.option_desc<? echo $i; ?>.focus();
return false;
}
<?
}
?>
return true;
}

//-->
</script>
<body>
<form method="post" action="#" name="poll_form" onsubmit="return checkform();">
<?
for ($i=0; $i<$num; $i++) {
?>
<p>
<input type="text" name="option_desc<? echo $i; ?>" size="50">
</p>
<?
}
?>
<input type="submit" name="submit">
</form>
</body>
</html>

The problem was making option_value[] a javascript array - Now it is a PHP one and it works fine!!!!


Still not sure what I was thinking the first time?

Simon


------------------
Simon Wheeler
FirePages -DHTML/PHP/MySQL

Reply With Quote
  #5  
Old June 17th, 2000, 11:04 PM
firepages's Avatar
firepages firepages is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: Perth West Australia
Posts: 741 firepages User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I must be on something today ! -

"The problem was making option_value[] a javascript array - Now it is a PHP one and it works "

option_value is no longer an array of any sort!

------------------
Simon Wheeler
FirePages -DHTML/PHP/MySQL

Reply With Quote
  #6  
Old June 18th, 2000, 02:59 AM
RayRay RayRay is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: Hong Kong
Posts: 71 RayRay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 10 m 50 sec
Reputation Power: 9
Thank you very much!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Javascript with PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT