IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Valeur d'un combobox via formulaire HTML


Sujet :

VBScript

  1. #1
    Membre averti
    Homme Profil pro
    Gestionnaire d'environnement et coordinateur technique de projet
    Inscrit en
    Mars 2014
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Gestionnaire d'environnement et coordinateur technique de projet

    Informations forums :
    Inscription : Mars 2014
    Messages : 13
    Par défaut Valeur d'un combobox via formulaire HTML
    Bonjour,

    J'ai pas mal cherché avant de venir ici et testé beaucoup de possibilité pour obtenir le texte contenu dans une option d'un combobox mais rien à faire, quoi que je fasse j'obtiens une valeur = ""...

    Le code utilisé.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    objIE.Document.Body.InnerHTML = "<div align=""center""><p>" & myPrompt _
    										& "</p><p><form name=""liste_form"" id=""Liste_form""></p>" _
    										& "<p><select name=""List"" id=""List"">" _
    										& "<option value=""Opt1"">bla</option>" _
    										& "<option value=""Opt2"">blo</option>" _
    										& "<option value=""Opt3"">bli</option>" _
    										& "<option value=""Opt4"">blu</option>" _
    										& "<option value=""Opt5"">ble</option>" _
    										& "<option value=""Opt6"">bly</option>" _
    										& "</select></p>" _
    										& "<input type=""hidden"" id=""OK"" name=""OK"" value=""0"">" _
    										& "<p><input type=""submit"" value="" OK "" " _
    										& "onclick=""VBScript:OK.Value=1""> " _
    										& "<input type=""submit"" value="" Annuler "" " _
    										& "onclick=""VBScript:OK.Value=2""></p>" _
    										& "</form></div>"
     
    		' Hide the scrollbars
    		objIE.Document.Body.Style.overflow = "auto"
    		' Make the window visible
    		objIE.Visible = True
     
    		objIE.Document.All.List.Focus
     
    		On Error Resume Next
    		Do While objIE.Document.All.OK.Value = 0
    			WScript.Sleep 200
    			' Error handling code by Denis St-Pierre
    			If Err Then    'user clicked red X (or alt-F4) to close IE window
    				IELogin = Array( "", "" )
    				objIE.Quit
    				Set objIE = Nothing
    				Exit Function
    			End if
    		Loop
    		On Error Goto 0
     
    		For Each opt In objIE.Document.getElementById("List").options
    			If opt.selected Then
    				GetValue = opt.text	
    			End If
    		Next
    Si vous avez des idées,

    Merci.

  2. #2
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut

    Une petite idée
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    Option Explicit
    Dim Titre
    Titre = "Valeur d'un ComboBox via formulaire HTML"
    MsgBox "Vous avez choisi l'option ==> " & IEForm(),64,Titre
    '************************************************************************************************************
    Function IEForm()
        Dim objIE
    ' Create an IE object
        Set objIE = CreateObject("InternetExplorer.Application")
    ' specify some of the IE window's settings
        objIE.Navigate "about:blank"
        objIE.Document.title = "MyForm" & String( 80, "." )
        objIE.ToolBar        = False
        objIE.Resizable      = False
        objIE.StatusBar      = False
        objIE.Width          = 320
        objIE.Height         = 150
    'Center the dialog window on the screen
        With objIE.Document.parentWindow.screen
            objIE.Left = (.availWidth  - objIE.Width ) \ 2
            objIE.Top  = (.availHeight - objIE.Height) \ 2
        End With
    'Wait till IE is ready
        Do While objIE.Busy
            WScript.Sleep 200
        Loop
    'Insert the HTML code to prompt for user input
        objIE.Document.body.innerHTML = "<div align=""center"">" & vbcrlf _
        & "<table cellspacing=""5""><tr nowrap>" _
        & "<form name=""liste_form"" id=""Liste_form""></p>" _
        & "<p><select name=""List"" id=""List"">" _
        & "<option value=""Opt1"">Hackoo</option>" _
        & "<option value=""Opt2"">Crackoo</option>" _
        & "<option value=""Opt3"">YOYOYO</option>" _
        & "<option value=""Opt4"">What time is it ?</option>" _
        & "<option value=""Opt5"">ble</option>" _
        & "<option value=""Opt6"">bly</option>" _
        & "</select></p>" _
        & "<p><input type=""hidden"" id=""OK"" " _
        & "name=""OK"" value=""0"">" _
        & "<input type=""submit"" value="" OK "" " _
        & "onClick=""VBScript:OK.value=1"">" _
        & "<input type=""submit"" value="" Annuler "" " _
        & "onClick=""VBScript:OK.value=10""></p></div>"
    ' Hide the scrollbars
        objIE.Document.body.style.overflow = "auto"
    ' Make the window visible
        objIE.Visible = True
    ' Set focus on input field
        objIE.Document.all.list.focus
     
    ' Wait till the OK button has been clicked
        On Error Resume Next
        Do While objIE.Document.all.OK.value = 0
            WScript.Sleep 200
            If objIE.Document.all.OK.value = 10 then
                wscript.echo "Annuler"
                objIE.Quit
                wscript.quit
            End If
            If Err Then    'user clicked red X (or alt-F4) to close IE window
                IEForm = Array("","")
                objIE.Quit
                Set objIE = Nothing
                wscript.quit
            End if
        Loop
        On Error Goto 0    
    ' Read the user input from the dialog window
        IEForm = objIE.Document.all.List.value
    ' Close and release the object
        objIE.Quit
        Set objIE = Nothing
    End Function
    '************************************************************************************************************

  3. #3
    Membre averti
    Homme Profil pro
    Gestionnaire d'environnement et coordinateur technique de projet
    Inscrit en
    Mars 2014
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Gestionnaire d'environnement et coordinateur technique de projet

    Informations forums :
    Inscription : Mars 2014
    Messages : 13
    Par défaut
    Bonjour,

    Merci,

    J'ai trouvé la solution vers midi, j'ai pas eu le temps de passer le post en résolu mais merci quand même.

    Bye

  4. #4
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut
    Citation Envoyé par nihlus Voir le message
    J'ai trouvé la solution vers midi
    Donc tu peux alors nous la partager ça peut aider d'autres personnes

  5. #5
    Membre averti
    Homme Profil pro
    Gestionnaire d'environnement et coordinateur technique de projet
    Inscrit en
    Mars 2014
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Gestionnaire d'environnement et coordinateur technique de projet

    Informations forums :
    Inscription : Mars 2014
    Messages : 13
    Par défaut
    Re.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    		objIE.Document.Body.InnerHTML = "<div align=""center""><p>" & myPrompt _
    										& "</p><p><form name=""liste_form"" id=""Liste_form""></p>" _
    										& "<p><select name=""List"" id=""List"">" _
    										& "<option value=""Opt1"">opt1</option>" _
    										& "<option value=""Opt2"">opt2</option>" _
    										& "<option value=""Opt3"">opt3</option>" _
    										& "<option value=""Opt4"">opt4</option>" _
    										& "<option value=""Opt5"">opt5</option>" _
    										& "<option value=""Opt6"">opt6</option>" _
    										& "</select></p></form>" _
    										& "<input type=""hidden"" id=""OK"" name=""OK"" value=""0"">" _
    										& "<p><input type=""submit"" value="" OK "" " _
    										& "onclick=""VBScript:OK.Value=1""> " _
    										& "<input type=""submit"" value="" Annuler "" " _
    										& "onclick=""VBScript:OK.Value=2""></p>" _
    										& "</div>"
     
    	' Hide the scrollbars
    	objIE.Document.Body.Style.overflow = "auto"
    	' Make the window visible
    	objIE.Visible = True
     
    	objIE.Document.getElementById("List").Focus
     
    	On Error Resume Next
    	Do While objIE.Document.getElementById("OK").Value = 0
    		WScript.Sleep 200
    		' Error handling code by Denis St-Pierre
    		If Err Then    'user clicked red X (or alt-F4) to close IE window
    			IELogin = Array( "", "" )
    			objIE.Quit
    			Set objIE = Nothing
    			Exit Function
    		End if
    	Loop
    	On Error Goto 0
     
    	If objIE.Document.getElementById("OK").Value = 1 Then
    		For Each opt In objIE.Document.getElementById("List").options
    			If opt.selected Then
    				GetValue_value = opt.text
    				Exit For
    			End If
    		Next
    	End If
    Le problème venait du balisage HTML qui était mauvais.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 12
    Dernier message: 10/04/2012, 10h28
  2. [MySQL] Envoi d'un INSERT INTO via formulaire HTML
    Par Patrice.H dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 06/04/2010, 23h02
  3. Réponses: 6
    Dernier message: 31/03/2010, 00h09
  4. ecrire des valeurs dans un tableau via formulaire
    Par kenny49 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 07/07/2006, 10h23
  5. [MySQL] Filtre via formulaire HTML/PHP dans Base mySQL
    Par Al3x dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 14/01/2006, 16h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo