/    Sign up×
Community /Pin to ProfileBookmark

passing variable javascript>PHP in the same script

[code=html]
<select name=”fonts” onChange=”update_master(‘fonts’, this.value);”>
<?php $fontsql = “SELECT * FROM pda_font”;
$query = mysql_query($fontsql) or die(mysql_error());

while ($row = mysql_fetch_object($query)) {
if($row->id == $thFont){
echo “<option value=”” . $row->id . “” SELECTED=”SELECTED”>” . $row->fontname . “</option>”;
} else {
echo “<option value=”” . $row->id . “”>” . $row->fontname . “</option>”;
}
}
?>
</select>
[/code]

This is an HTML “select” object, being populated with font names arranged by their db index numbers.

Even though the name of the font is what is displayed in the object, The Client wishes another display onscreen beside it, showing the same name.

The form (“update_master”) to which “this.value” is being sent is pointed at another page which is purely PHP. I’ve tried to embed the HTML display in that page and have not succeeded.

I could of course query the database again.

Way up this script is a function in which I’ve declared a global $fName.
And, in another section of this script, I’ve declared the JavaScript var aaa.

So at one point I tried,

[code=html]<select name=”fonts” onChange=”aaa = this.value; update_master(‘fonts’, aaa);<?php $fName=aaa; ?>;”>
[/code]

The form updated properly, but all I got in the readout was “aaa”.

Is there any way I could set $fName = (aaa)??

Any help will be considered life-saving…

Thanks,
Paul

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@freedmaniaauthorSep 06.2008 — Um, is the subject too boring, or

does the question not make sense, or

is there no way to pass a value from an onclick event to a PHP variable other than submitting a form?

If there isn't any other way, can you send an html form to two targets simultaneously?

And, can one of those targets be in the same script as the onclick event?
Copy linkTweet thisAlerts:
@UltimaterSep 06.2008 — Read into Ajax, JavaScript's XMLHttpRequest object.
Copy linkTweet thisAlerts:
@DokSep 06.2008 — A select tag does not have any value property so when passing 'this.value' it is null.

To get the value of the selected option in a select do this
[CODE]<select name="fonts" onChange="update_master('fonts', this.options[this.selectedIndex].value);">[/CODE]
Copy linkTweet thisAlerts:
@UltimaterSep 06.2008 — A select tag does not have any value property so when passing 'this.value' it is null.[/QUOTE]
Umm... No. You're thinking of [i]text[/i] or have been debugging with a really old browser.

Even on these forums, tossing the following into your browser address bar will prove my point:
<i>
</i>javascript:alert(document.getElementsByTagName("select")[0].value)

Point made. You may be right as far as support for ancient browsers and it is probably better to write it out the long way for that reason yet the short version mustn't be discouraged or thought invalid syntax. It's pretty much the same difference between myArray[myArray.length]=el; and myArray.push(el);

I personally stick with the long version since the Array's push method can be tampered with and I like to avoid function calls when possible.
Copy linkTweet thisAlerts:
@DokSep 06.2008 — Umm... No. You're thinking of text or have been debugging with a really old browser.[/QUOTE]Niether...I'm just really slow and stupid ? I actually didn't know that...how embarrasing.

ToDo List: In future post check my facts.
×

Success!

Help @freedmania 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.19,
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,
)...