/    Sign up×
Community /Pin to ProfileBookmark

image src=variable

the task i am trying to complete is getting a field from a sql database to check against with javascript that will in turn set a variable for an image src.

in the body of the html i would like to say
<img src= “variable” alt=”” />

the javascript i have so far is this
<script type=”text/javascript”>
dbField=0
function GetdbField()
{
dbField = document.getElementById(“FieldFromDataBase”);
//alert(dbField.value);
return dbField.value;
}
if
{
dbField.value = ‘1’ then var var1 = ‘imagesimage1.jpg’ }
else
{
var var1 = ‘imagesimage2.jpg’ }
</script>

Any suggestions and help will be greatly appreciated!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NatdripMar 27.2008 — javascript is not a server side language.

when you want to talk to a database.

you will need to use something like php, asp ,java , .net ...etc.

once you query the DB using SQL

you will gather the requested information in a record source object.

then using ajax, iframe, and or some other imbeded object you would return the relative information to the javascript variable then launch a function that returns compares what you have with what you want.

:eek:

hope this helps
Copy linkTweet thisAlerts:
@bretnoauthorMar 28.2008 — the db fields are already available behind the html page...

I am able to get the fields with document.getElementById("");

I just need to know how to check the value with javascript to set variable for image source.

Hope this makes sense!

?
×

Success!

Help @bretno 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...