javascript add image to varible

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
User avatar
JanMolendijk
Posts: 224
Location: Holland Rotterdam

javascript add image to varible

Hello Coursesweb I do not known mutch about javascipts
& for view hours I gambling to try to get images in this javascript

I try with (example)

Code: Select all

 case 1 :  return  "Spades.png";
to add it in

Code: Select all

 <TD align=middle>Card(s):<INPUT  type="text1" onfocus=guest.blur(); this.src=getImagePath(); size=4 
      value="Push DEAL to start" name=guest>

Hope you van help me out ????



Code: Select all

<SCRIPT language=JavaScript> 


 
<!-- BEGIN --
 
var GameOver  = 0;
var CardCount = 0;
var Advising  = 0;
var HouseTxt, GuestTxt;
 
function Shuffle(max)
{
	num=Math.random()*max; 
	return Math.round(num)+1;
}


function myFunction() {
  var x = document.getElementById("suit").src;
  document.getElementById("demo").innerHTML = x;
}

 
function GetSuit() {


  suit = Shuffle(4);


	switch(suit) 
	{

	
	case 1 :  return  "Spades.png";
       case 2 : return "Clubs.png";
        case 3 : return  "<img src='Diamonds.png' />"; 
	
      default: return  "Hearts.png"; 
	}
}
 
function CardName(card)
{
	switch(card) 
	{
		case 1  : return "Ace";
		case 11 : return "Jack";
		case 12 : return "Queen";
		case 13 : return "King";
	case 2 : return "Molendijk";
		default : return  card;

	}
}
 
function CardValue(f,card,who)
{
  if(card == 1) 
	{
		if(who == "You" && f.you.value >10)
		{
			f.guest.value = f.guest.value + " Low"; 
			return 1;
		}
	 	  else return 11; 
	}
   if(card > 10) return 10; 
   return card;
}
 
function DrawCard(f,who)
{
  card = Shuffle(12);
  suit = GetSuit();
   
	if(who == "You")
  {
		f.guest.value=(CardName(card) + " " + suit);
	}
    else
  {
		f.house.value=(CardName(card) + " " + suit);
	}
 	
	return CardValue(f,card,who);
}
 
function NewHand(f)
{
	if(GameOver !=0)
  {
		Advise(f,"A Hand is","Already in Play");
		return;
	}
   else
  {
		f.dealer.value = 0; 
		f.you.value = 0; 
		CardCount=0;
   	f.dealer.value = eval(f.dealer.value) + DrawCard(f, "Dealer");
   	f.you.value = eval(f.you.value) + DrawCard(f, "You");
		GameOver= -1; 
		CardCount+=1;
	}
}
 
function Advise(f,top,btm)
{
  if (!Advising)
  {
  Advising=-1;
  HouseTxt=f.house.value;
  GuestTxt=f.guest.value;  
  f.house.value=top;
  f.guest.value=btm;
  window.setTimeout("document.display.house.value=HouseTxt;"+
                    "document.display.guest.value=GuestTxt;"+
                    "Advising=0;", 600);
  }
}
 
function Dealer(f)
{
	if (!GameOver)
	{
		Advise(f,"Deal the Cards!",""); 
		return;
	}
		else if(f.you.value<10)
  {
		Advise(f,"Not Below Ten!","Take a Hit!"); 
		return;
	}
		else if (CardCount <2)
  {
		Advise(f,"Minimum 2 Cards!","Hit Again!");  
		return;
	}
		else while(f.dealer.value < 17)
  {
		f.dealer.value = eval(f.dealer.value) + DrawCard(f, "Dealer");
	}
}
 
 
function Player(f)
{
	if (!GameOver)
	{
		Advise(f,"Deal the Cards!",""); 
		return;
	}
		else
	{
		CardCount +=1; 
		f.house.value="You Get...";
    f.you.value = eval(f.you.value) + DrawCard(f, "You");
	}
   
	if(f.you.value > 21)
	{
		f.house.value="You Busted!";
	 	GameOver=0; 
		f.score.value=eval(f.score.value)-1;
	}
}
 
function Declare(f)
{
	if (!GameOver || f.you.value<10 || CardCount <2)
	{
		return;
	}
		else if(f.dealer.value > 21)
	{
		f.house.value="House Busts!"; 
		f.guest.value="You Win! $$$$$$";
	  GameOver=0; 
		f.score.value=eval(f.score.value)+1;
	}
   	else if(f.you.value > f.dealer.value)
	{
		f.house.value="You Win!"; 
		f.guest.value="$$$$$$$$$$$$$$$";
	 	GameOver=0; 
		f.score.value=eval(f.score.value)+1;
	}
   	else if(f.dealer.value == f.you.value)
	{
		f.house.value="Game Tied!"; 
		f.guest.value="Try Again!";
	 	GameOver=0; 
		f.score.value=eval(f.score.value)-1;
	}
   	else
	{
		f.house.value="House Wins!"; 
		f.guest.value="Tough Luck!";
		GameOver=0; 
		f.score.value=eval(f.score.value)-1;
	}
}
 
// -- END -->
 
</SCRIPT>

Code: Select all

<CENTER>
<FORM name=display>
<TABLE cellSpacing=0 cellPadding=5 border=0 bgcolor="#D8D8D8">
  <TBODY>
  <TR>
    <TD align=middle>Score :</TD>
    <TD align=middle>Dealer </TD>
    <TD align=middle><INPUT type="textgamers" onfocus=dealer.blur(); size=4 name=dealer></TD>
    <TD align=middle>Card(s):<INPUT type="text1" onfocus=house.blur(); size=18 id=searchbar 
      value=" ---Blackjack---" name=house></TD>
  </TR>
  <TR>
    <TD align=middle><INPUT  type="textgamers" onfocus=score.blur(); size=4 value=0 name=score></TD>
    <TD align=middle>Player</TD>
    <TD align=middle>

<INPUT type="textgamers" size=18 onfocus=you.blur(); size=4 name=you></TD>
    <TD align=middle>Card(s):<INPUT  type="text1" onfocus=guest.blur(); this.src=getImagePath(); size=4 
      value="Push DEAL to start" name=guest>



</TD></TR>


  <TR>
    <TD align=middle> 
    </TD>
    <TD align=middle colSpan=3> <INPUT onclick=NewHand(this.form) size=18  type=button value=Deal name=deal>
 <INPUT onclick=Dealer(this.form);Declare(this.form) type=button value=Stand> 
<INPUT onclick=Player(this.form) type=button value=" Hit "> 
</TD></TR></TBODY></TABLE></FORM></CENTER>

Admin
I not understand what variable you refer.
Where do you want to add the image, into a TD element?
When, or in which conditions the image will be added?

JanMolendijk
From the suit I try to get all cards with picture
added in the TD element.

Code: Select all

switch(suit) 
	{
	case 1 :  return  "Spades.png";
       case 2 : return "Clubs.png";
        case 3 : return  "<img src='Diamonds.png' />"; 
	
      default: return  "Hearts.png"; 
All variables cards results comes in this element

Code: Select all

<TD align=middle>Card(s):<INPUT  type="text1" onfocus=guest.blur(); this.src=getImagePath(); size=4 
      value="Push DEAL to start" name=guest>
I hope my bad English is understanble.

Admin
It isn't about your english, but i have no more interest in web-development and web programming.
I want to discover the truth about me, life, and what people call God.

JanMolendijk
You had the best support on the internet,
mutch better then stackoverflow.

i learnt alot from you it was really valuable
+ Thanks for all you did for me & everyone else

In the Netherlands I am also a member of a church,
they do good things for Rotterdam that deserve support

God bless

Similar Topics