If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Javascript with PHP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-06-03, 14:26
cmptrguru7 cmptrguru7 is offline
Registered User
 
Join Date: Feb 2002
Posts: 43
Javascript with PHP

Can anyone tell me whats wrong with this code. It gets called from an onSubmit statement in the form code. The alert is shown, but the function always returns true. If I take the if statement out and just return false then it works properly. Any suggestions?

<? echo("<script Language=\"JAVASCRIPT\">

function ValidateForm()
{
alert (\"Test alert\");

if (username==\"validuser\")
{
return true;
}
else
{
return false;
}

}
</script>"); ?>
Reply With Quote
  #2 (permalink)  
Old 08-27-03, 18:25
Shores Shores is offline
Registered User
 
Join Date: Aug 2003
Location: Bologna - Italy
Posts: 209
If what you're saying is that you have a form with a field named "username", and you want to check for the value it contains, then you should write it this way:

document.forms[0].elements["username"].value=="validuser"

Bye!
__________________
The only failure is not trying to do it.
Reply With Quote
  #3 (permalink)  
Old 09-28-03, 02:11
sarahk sarahk is offline
Registered User
 
Join Date: Sep 2003
Location: New Zealand
Posts: 6
where does the PHP come into it? Is the alert after the form has been processed or prior to the submit happening?
Reply With Quote
  #4 (permalink)  
Old 09-30-03, 16:40
moku moku is offline
Registered User
 
Join Date: Sep 2003
Location: Wisconsin, USA
Posts: 34
DOM

sarah - This is a javascript question, unrelated to PHP.

shores - You've got it right.

cmptguru - You need to study how javascript works before trying to write PHP code that generates javascript Mainly study the DOM (Document Object Module), which is how you use javascript to interact with the html document.

There are many ways to do this very thing depending on your target audience (how old their browser is and if it's IE or something else) and how your page is layed out.

May I suggest
http://www.w3schools.com/js/default.asp
and
http://www.w3schools.com/dhtml/default.asp
Reply With Quote
  #5 (permalink)  
Old 10-01-03, 01:15
sarahk sarahk is offline
Registered User
 
Join Date: Sep 2003
Location: New Zealand
Posts: 6
Re: DOM

Quote:
[SIZE=1]Originally posted by moku
sarah - This is a javascript question, unrelated to PHP.
Duh, I could see that! I was trying to find out from cmptrguru7 what exactly was going on so I take him/her a step further.

Using Javascript & PHP together is one of the biggest mental hurdles for some coders I reckon.
Reply With Quote
  #6 (permalink)  
Old 10-01-03, 10:46
moku moku is offline
Registered User
 
Join Date: Sep 2003
Location: Wisconsin, USA
Posts: 34
sarahk

Sorry sarah, I knew you realized that. Javascript + PHP -is- a pretty big challenge at first.

I was just flying through some responses and I guess I made that one a little too short. ... should have put "sarah - You're right, this is a javascript problem"

cmptguru: any questions / problems?
Reply With Quote
  #7 (permalink)  
Old 10-01-03, 21:23
cmptrguru7 cmptrguru7 is offline
Registered User
 
Join Date: Feb 2002
Posts: 43
I have solved my problem thank you for your help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On