/    Sign up×
Community /Pin to ProfileBookmark

Javascript + PHP

I am trying to assign a php variable to take the value from a textbox and i tried to transfer the value from the textbox to the php variable in javascript embedded inside a php script.

Apparently, it is not working and i must be doing something wrong. Can someone help me out here? Thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@MauAug 24.2005 — Can you restate what you are trying to do? I don't follow.
Copy linkTweet thisAlerts:
@shaoen01authorAug 24.2005 — Sorry. Okay basically i have a textbox1 in my form and i want to assign a php variable (called A) to take textbox1 value. And both textbox1 and A php variable is in the same form or script. How do i do that in php coding?

Are you follow me better?
Copy linkTweet thisAlerts:
@MauAug 24.2005 — You first need your form with textbox1 in it:

<i>
</i>&lt;form action="&lt;?php print $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
&lt;textarea name="textbox1"&gt;&lt;/textarea&gt; &lt;!-- your text box --&gt;
&lt;/form&gt;


Next, you need your PHP code. Because this form is being submitted as a "post" request, all the data in this form will appear in the superglobal, $_POST.

[code=php]
if (!empty($_POST['textbox1'])) $textbox1 = $_POST['textbox1']; // this line fills $textbox1 when there is something to fill it with (that's what the if statement is for). If no data was sent through POST, then $textbox1 doesn't change
[/code]


So, your completed script looks something like this:
[code=php]
<?php
if (!empty($_POST['textbox1'])) $textbox1 = $_POST['textbox1']; // this line fills $textbox1 when there is something to fill it with (that's what the if statement is for). If no data was sent through POST, then $textbox1 doesn't change
?>

<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="textbox1"></textarea> <!-- your text box -->
</form>
[/code]


I think that's what you are asking. Let us know if it works or doesn't ?

Untested.
Copy linkTweet thisAlerts:
@shaoen01authorAug 24.2005 — Thanks for you help.

I know this code below will help set the value of the input value for me:

[Code]
<input type="text" id="zipfilename" name="zipfilename" value="<?php echo $zipfilename ; ?>">
[/Code]


Is there anyway i can edit the current value of my input, zipfilename, later after i have inserted the code above?

I have tried to edit the value by using javascript but it does not show when i right click on IE and view source. Do you know why it is so?

[Code]
echo '<script language="JavaScript" type="text/javascript" >' ;
echo "document.downloadForm.zipfilename.value='".$zipfilename."'" ;
echo '</script>' ;
[/Code]
×

Success!

Help @shaoen01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...