method is not defined

not sure if this a javascript problem or the way i have it in HTML but

Page 1 of 1

1 Replies - 1327 Views - Last Post: 05 March 2009 - 12:04 AM

#1 mweaver84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-December 08

method is not defined

Posted 04 March 2009 - 09:39 AM

my first page is

form method="GET" action="result.html">
First Name: <input type="text" name="fname" />
<br />
Last Name: <input type="text" name="lname" />
<br /><br />
<input type="submit" value="Submit" />
</form> 



second page is, just want to use the gup function to find the values of the the fname and lname in the URL... but method keeps getting method is not defined when i run it.

<html>
<head>
<script type="javascript">


function gup( name ){ 
 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 var regexS = "[\\?&]"+name+"=([^&#]*)";
 var regex = new RegExp( regexS ); 
 var results = regex.exec( window.location.href );
 if( results == null ) 
 return "";
 else 
 return results[1];}

</script>
</head>

<body>
<script language="Javascript">
var ln = gup('lname');
var fn = gup('fname');
document.write(fn);
document.write(ln);
</script>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: method is not defined

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4438
  • View blog
  • Posts: 12,309
  • Joined: 18-April 07

Re: method is not defined

Posted 05 March 2009 - 12:04 AM

I ran your test through the following page setup and it was fine for me. I get no error what so ever with this.

<html>
<head>
<title></title>
<script language="Javascript">
function gup( name ){
 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 var regexS = "[\\?&]"+name+"=([^&#]*)";
 var regex = new RegExp( regexS );
 var results = regex.exec( window.location.href );
 if( results == null )
 return "";
 else
 return results[1];}

</script>
</head>

<body>
<script language="Javascript">
var ln = gup('lname');
var fn = gup('fname');
document.write(fn);
document.write(ln);
</script>


<form method="GET" action="test.htm">
First Name: <input type="text" name="fname" />
<br />
Last Name: <input type="text" name="lname" />
<br /><br />
<input type="submit" value="Submit" />
</form> 

</body>
</html>



This form submits to itself called "test.htm" and the javascript picks up the passed parameters from the form and displays them on the page. What line is it pointing out to as having the problem?

As far as I can tell there is nothing wrong other than perhaps you missing the "<" before the word "form" on your form. But I don't know if that was just a typo or not.

:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1