Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 09-24-2008, 09:02 AM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
JS form wackjob!!

Hello all,

I'm expierencing a very weird problem.

Firstly, My main code script is PHP I'm writing a WebApplication with it.
In one of my forms I've found the need to have a select input onchange run a javascriptlet that changes the forms action location and then submits it.

The problem I keep getting is that JS keeps bringing the forms action value back as [object] instead of mypage.php

HOWEVER!, When I pull the code out of that page and make a strip down version of it. It works perfectly.

Now that makes me think that theres something hindering it on the php side.
Well when I check the "ViewSource" on the html output from the php code.

The HTML output is perfectly written. Exactly as in my test page. So why is on one hand JS seeing the form action as [object] then on the other hand with no changed code. It sees the correct action value????

code i'm using

Code:
<script> function GetEmpDetails() { document.getElementById('TheForm').action='NewPage.php'; document.getElementById('TheForm').submit(); } </script>
Code:
<html> <form id='TheForm' name='TheForm' action='FirstPage.php' method='post'> <select name='Emps' onchange='GetEmpDetails();'> <option value='1'>Emp1</option> <option value='2'>Emp2</option> </select> </form>
</html>
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 09-24-2008, 11:26 AM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
Well, you can try
document.getElementById("theForm").setAttribute("a ction", "NewPage.php");

The core problem could be that some js library overrides the getElementById function.
 
Reply With Quote
  #3  
Old 09-24-2008, 11:59 AM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
Ok I tryed that .. It sort of worked.. it atleast tryed to submit.. But I'm thinking that it still skipped over the action setting.

Now I'm getting this error:

Expecting ')'
 
Reply With Quote
  #4  
Old 09-24-2008, 12:02 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
I don't have any JS libs that are attached to the page.. I try not to use JS unless absolutely needed.
 
Reply With Quote
  #5  
Old 09-24-2008, 12:07 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
I don't see any place to put another ) in the script so I'm guessing it just saying that because it a bug
 
Reply With Quote
  #6  
Old 09-24-2008, 12:08 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
Code:
<script> function GetEmpDetails() { document.getElementById('TheForm').setAttribute('action','EmpHours.php'); document.getElementById('TheForm').submit(); } </script>
 
Reply With Quote
  #7  
Old 09-24-2008, 12:11 PM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
Could you post the url? (or PM me).
 
Reply With Quote
  #8  
Old 09-24-2008, 12:21 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
PM'ED
 
Reply With Quote
  #9  
Old 09-24-2008, 12:41 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
Ok I got something going here THERE IS LIFE!!!!!

I think it wasn't recognizing the ending form tag.. Just cuz i'm at my witts end here I decided I"d end the form right after the first selection input..

Tried it and BAM frikin worked..

Now my question is .. why won't it work with the rest of the form?
 
Reply With Quote
  #10  
Old 09-24-2008, 12:47 PM
nasty.web nasty.web is offline
v7n Mentor
 
Join Date: 07-24-06
Posts: 688
iTrader: 1 / 100%
try returning true or false from GetEmpDetails() function.
 
Reply With Quote
  #11  
Old 09-24-2008, 01:03 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
I fixed the one error on the Ceh_info page..

I've got the script setup like this now..

Code:
<script> function GetEmpDetails() { document.getElementById('TheForm').action='EmpHours.php'; document.getElementById('TheForm').setAttribute('action','EmpHours.php'); /*document.getElementById('TheForm').submit();*/ alert(document.getElementById('TheForm').action); } </script>
 
Reply With Quote
  #12  
Old 09-24-2008, 01:15 PM
ag3nt42's Avatar
ag3nt42 ag3nt42 is offline
Member
 
Join Date: 04-22-08
Posts: 119
iTrader: 0 / 0%
Nasty YOU ROCK..

I changed the submit buttons names to Button instead of action and bam she works...

Whats crazy to me is that JS is confusing an elements Name with another elements Property.. I guess JS's lil variable setting system isn't so wise after all..

Thats the only thing I could contribute it to...

Var action= 'this';
action='this';

both same.. if they would not allow the second way of setting the variable we probably wouldn't be dealing with this problem right now.
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Contact form please help to create a contact form jennypretty Coding Forum 2 07-03-2008 07:49 AM
Web Form mrcountry Web Design Lobby 3 03-19-2008 08:55 PM
Can't show non-modal form when modal form is displayed sypond Coding Forum 3 03-23-2007 08:31 AM
there's a form down, form down drew68 Coding Forum 2 08-02-2006 10:45 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 12:11 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC