473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

embeding javascript in anchor tag

omerbutt
638 512MB
hi i am trying to use javascript in the anchor tag within the href attribute but it is not picking the value instead it is posting the javascript as a text when i click that link here are the combination i have already tried.
Expand|Select|Wrap|Line Numbers
  1. <a href="index.php?nxId=document.getElementById('questions').options[document.getElementById('questions').selectedIndex].value"></a>
  2.  
  3. <a href="index.php?nxId=<script type='text/javascript'>document.getElementById('questions').options[document.getElementById('questions').selectedIndex].value</script>"></a>
  4.  
  5. <a href="index.php?nxId=<?php echo '<script type='text/javascript'>document.getElementById('questions').options[document.getElementById('questions').selectedIndex].value</script> ?>"></a>
  6.  
  7.  
any help in this regard
Omer Aslam
Dec 2 '09 #1
5 1986
RamananKalirajan
608 512MB
Hi Omer,
Why cant you have a function and set the values through that, instead of setting in the href itself?

Thanks and Regards
Ramanan Kalirajan
Dec 2 '09 #2
omerbutt
638 512MB
i already did it via ajax but myt senior said that the application is to be used with in the intranet not online and it is more possible that such applications will fail due to not having javascript enabled on their machine so everything should be done via php
regards,
Omer Aslam
Dec 2 '09 #3
Dormilich
8,658 Expert Mod 8TB
neither of your lines is correct. the first one is not recognised as JavaScript and the latter are violating the HTML syntax (thus it is also not executed).

cou can use PHP only after the form submit and it will not react upon immediate changes. if you use AJAX to submit those changes to the server, you can as well use standard JavaScript to do the same and just change the href.

the embedding works only, if you have an event handler defined.
Dec 2 '09 #4
omerbutt
638 512MB
yeah as i told i had already done it through AJAX it woz a piece of cake but now its irritating me :(
Dec 3 '09 #5
acoder
16,027 Expert Mod 8TB
i already did it via ajax but myt senior said that the application is to be used with in the intranet not online and it is more possible that such applications will fail due to not having javascript enabled on their machine so everything should be done via php
You do realise:
1. If you have JavaScript disabled, none of these attempts will work even if you had the correct syntax,
2. On the intranet, you have more control over the settings. You can ensure that everyone has JavaScript enabled.

If you want to do everything via PHP, use a form and submit.
Dec 3 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: nam | last post by:
could someone please help me with this bizarre problem - I've created a swf file at the top of my html page. The swf file (using Swish) is simply a menu of 5 links to 5 anchor points on the html...
3
by: bigbinc | last post by:
set scroll position in javascript. Is there a way to do this without using document.location, example. document.location = "#gohere" <a name="gohere">
12
by: Howard Kaikow | last post by:
Yesterday, I decided to try Firefox. I've encountered a behavior that is either a bug in Firefox or a bug in my Javascript code. I'll try to explain the problem, hoping that this newsgroup can...
9
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE...
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
11
by: yawnmoth | last post by:
If using an onclick event handler to execute javascript when an anchor element is clicked on, what should the href attribute be? #? javascript:void(0)? Something else?
1
by: umamy | last post by:
Hi, I am writing code to do the followin: - user clicks a link - the page reloads and sets a cookie with a js function in the header. The function reloads the same page with the cookie set and...
10
by: Edwin Knoppert | last post by:
I have an asp.net imagebutton with a clickevent. I have enclosed an anchor around the image and a small text. If i click the image the event is executed (while the href of the anchor shows in the...
12
by: wavedancer | last post by:
I just tried validating the page I'm working on as <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> and it fails on the PayPal...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.