By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

using javascript function in php function??

P: n/a
Can anyone see why the checkbox in the code below doesnt get ticked when the
textbox is changed
***This javascript function is called in the textbox's onchange event to
check it when it is changed*****

<script type="text/JavaScript">
function changed(x){
document.getElementById(x).checked=true;
}
</script>
******This php function determine whether the check box is shown or not
(actually does more than this but ive slimed down the code) and has the
javascript function in the onChange event of the echoed textbox

function editable($edfield,$unedfield,$xtratext,$selquest){
if($unedfield!==''){
echo $xtratext."<input type='text' class='BodyText' style='WIDTH:
85%' name='".$edfield."' onChange='changed(".$selquest.")>'
value='".$unedfield."'><br>" ;
}else{
echo '';
}
}

************The code below displays the check box to be ticked and the text
box (or blank) fron the execution of the php function (editable)*********

<input name="changed[]" type="checkbox" id="<?php echo $QuestionIndex; ?>"
value="<?php echo $QuestionIndex; ?>">
<?php editable($groupcount,'question',$Question,1,'') ?>

I suspect it could be due to using a javascript function in php function.
I'm not sure if this is allowed. If anyone can see what wrong Id be very
grateful

Thank Ian
Oct 12 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
mantrid wrote:
I suspect it could be due to using a javascript function in php function.
I'm not sure if this is allowed.
JavaScript and PHP have *nothing* to do with one another.
(Read this http://xkr.us/js/clientserver three times so that you
understand it.)

PHP produces X/HTML. The web browser sees that code. Now JavaScript
comes into play.

View Source on your web page to see what code is actually coming out,
and then you will see why your HTML may or may not be broken. That's
all the browser cares about.

Oct 12 '06 #2

P: n/a
I know you can echo javascript but you have to make sure its placed in
the body because some of the java script doesnt work in the header. I
used php to echo(print it) javascript for a photogallery. if you want
any of the code to see what it looked like i can send it to you. if you
cant see if you can do what the guy above me said and see if you can
just test the java script or see what teh html out put is. any
questions just message me if you have any more questions.

Oct 12 '06 #3

P: n/a
Phrogz wrote:
mantrid wrote:
I suspect it could be due to using a javascript function in php function.
I'm not sure if this is allowed.

JavaScript and PHP have *nothing* to do with one another.
(Read this http://xkr.us/js/clientserver three times so that you
understand it.)

PHP produces X/HTML. The web browser sees that code. Now JavaScript
comes into play.

View Source on your web page to see what code is actually coming out,
and then you will see why your HTML may or may not be broken. That's
all the browser cares about.
You may also want to use Mozilla's Web Developer Toolbar, it's very
helpful in debuging JavaScript code.

Hope this helps.

Oct 12 '06 #4

P: n/a
OK
I got it just a silly typo error in my function. It should be

echo $xtratext."<input type='text' class='BodyText' style='WIDTH: 85%'
name='".$edfield."[]' value='".$unedfield."'
onChange='changed(".$selquest.")'><br>" ;

or for a text area (later part of the function not shown)

echo $xtratext."<textarea class='BodyText' style='WIDTH: 98%'
name='".$edfield."[]'
onChange='changed(".$selquest.")'>".$unedfield."</textarea><br>";

Thanks all for your time

Ian

"mantrid" <ia********@virgin.netwrote in message
news:2Z****************@newsfe7-win.ntli.net...
Can anyone see why the checkbox in the code below doesnt get ticked when
the
textbox is changed
***This javascript function is called in the textbox's onchange event to
check it when it is changed*****

<script type="text/JavaScript">
function changed(x){
document.getElementById(x).checked=true;
}
</script>
******This php function determine whether the check box is shown or not
(actually does more than this but ive slimed down the code) and has the
javascript function in the onChange event of the echoed textbox

function editable($edfield,$unedfield,$xtratext,$selquest){
if($unedfield!==''){
echo $xtratext."<input type='text' class='BodyText'
style='WIDTH:
85%' name='".$edfield."' onChange='changed(".$selquest.")>'
value='".$unedfield."'><br>" ;
}else{
echo '';
}
}

************The code below displays the check box to be ticked and the
text
box (or blank) fron the execution of the php function (editable)*********

<input name="changed[]" type="checkbox" id="<?php echo $QuestionIndex; ?>"
value="<?php echo $QuestionIndex; ?>">
<?php editable($groupcount,'question',$Question,1,'') ?>

I suspect it could be due to using a javascript function in php function.
I'm not sure if this is allowed. If anyone can see what wrong Id be very
grateful

Thank Ian


Oct 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.