Dynadot โ€” .com Registration $8.99

JavaScript and PHP Help 50np reward

Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
167
What im doing is trying to take a username var from javascript and post it to a php document in an inline frame.

<
HTML:
form method="POST" action="edit.php" target="I2"><input type="hidden" name="usrname" value="javascript: document.getElementById('username').value">
<textarea rows="2" name="profile" cols="56"></textarea><br><input type="submit" value="Save Profile" name="B1"></form>
	<p>
	<iframe name="I2" width="294" height="28" src="edit.php" frameborder="0"></iframe>

is that corrent, because it doesnt seem to be working write.. the php end of it works fine, as it is an onpost and has been tested with an html var..

Im rewarding 50NP to the one that provides a solution that works
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Code:
<script language="javascript">
  var username = "Sjaguar13";

  function inputUsername(obj){
    obj.usrname.value = username;
       return true;
  }
</script>

<form method="POST" action="edit.php" target="I2" onSubmit="return inputUsername(this);">
<input type="hidden" name="usrname">
<textarea rows="2" name="profile" cols="56"></textarea>
<br>
<input type="submit" value="Save Profile" name="B1">
</form>

	<p>
	<iframe name="I2" width="294" height="28" src="edit.php" frameborder="0"></iframe>

The Username field is spelled usrname for the PHP. I don't know if that's a typo or not, but if the PHP has username coming up blank, make sure it's getting the field usrname and not username.
 
0
•••
well the script im using already has the username defined... should i still use the function input username?

and no usrname isnot a typo
 
0
•••
im not a javascript wiz, but doesnt this line:

value="javascript: document.getElementById('username').value"

need a semicolon in there somewhere? compared to all other javascript, it needs semicolons.
 
0
•••
templaterave said:
well the script im using already has the username defined... should i still use the function input username?

Yes, you can put that function in the same script tags as the JavaScript that defines username.

nasaboy007 said:
m not a javascript wiz, but doesnt this line:

value="javascript: document.getElementById('username').value"

need a semicolon in there somewhere? compared to all other javascript, it needs semicolons.
Inline JavaScript doesn't absolutely have to have a semicolon. It probably should, but not necessary (it works either way). The problem is inline JavaScript doesn't work in this situation. The value is taken as a literal and would submit the whole string to the php script.
 
0
•••
Hi. Can I just ask:

- Is it completely necessary to use javascript? Cant you use PHP to store the variable?
- Is it completely necessary to use an iframe? That a) causes problems in browsers that don't support iframes and b) causes problems in your script.

I don't know what you are doing, but you could probably do a better job if you just used one language. Using two would be hard/complicated but trying to mix them is suicidal. There are always obstacles you could easilly get round if you just used one language.
 
0
•••
you should just use cookies, alot easier, and more secure.
 
0
•••
Have you tried adding an "ID" att to the iframe?
HTML:
<iframe name="I2" id="I2" width="294" height="28" src="edit.php" frameborder="0"></iframe>

That may make it work. I can't see any other problems with your code, but if you were to do it in php it would tell you what was wrong.
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back