Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to send string parameters to a javascript function from php? 3

Status
Not open for further replies.

ejocobip

Programmer
Feb 11, 2005
13
US
Hello, if anyone can help me? i'm trying to send string parameters to javascript funcion from php but only worked with numeric values

Code:
<script type="text/javascript"> 
	function del_carrier(idcarrier) {
	   aler("deleted "+idcarrier);
	}
</script> 

<? echo "<a href=# onClick='del_carrier('$scaccode');'>Delete"; ?>

with this code the funcion sends my string like a variable name, someone know how to work this out?
Regards,
Patty
 
Hello feherke, thanks for your reply,

I have already try that but didn't work, the error that javascript gives me, is that the string i send is undefined i think it takes my string like a variable name

Error: 'My String' is undefined

any ideas?

thanks for your help :)
 
Would you need to escape the $?

Code:
<? echo "<a href=# onClick=\"del_carrier('[!]\[/!]$scaccode');\">Delete"; ?>




[monkey][snake] <.
 
Hi

Are you sure, [tt]short_open_tag[/tt] is enabled in your php.ini ?

My sugestion works for me :
Code:
<?php
$scaccode="lol";
?>
<html>
<head>
<script type="text/javascript">
function del_carrier(idcarrier)
{
  alert("deleted "+idcarrier);
}
</script>
</head>
<body>
<?php echo "<a href=# onClick=\"del_carrier('$scaccode');\">Delete</a>"; ?>
</body>
</html>
Please confirm that the generated HTML document is correct, otherwise would be better to continue this in forum434 ( PH P ).

Feherke.
 
Hello monksnake,

I try it out and didn't work :( I guess if I don't find any more options i will create a autonumeric index for my tables hehe..

mmm I hope somebody help me with this issue

thanks...
 
Do what feherke suggested and what I completely missed (close the </a> tag).

Have a * feherke for not looking past the obvious.

[monkey][snake] <.
 
hi guys thanks a lot for the help,

I close the </a> tag, and verify in php.ini and verify that the short_open_tag is On, but didn't worked, maybe is something in my web browser? i think the problem is with the javascript

what do you guys think?
 
Hi

Personally I think that you should
[ul]
[li]copy & paste my code sample into a new file[/li]
[li]request that new file into your browser[/li]
[li]open the View Source for that page[/li]
[li]copy & paste the page source here[/li]
[/ul]

Feherke.
 
Thanks guys finally it worked

<?php echo "<a href=# onClick=\"del_carrier('$scaccode');\">Delete</a>"; ?>

like feherke told me, I don't know what I was missing, but i type it again because my eyes couldn't see the error hehe..

have a great day :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top